package com.hycat.mail.search.controller;

import com.hycat.mail.common.exception.MailException;
import com.hycat.mail.common.model.ExceptionEnum;
import com.hycat.mail.common.to.es.SkuEsModel;
import com.hycat.mail.common.utils.R;
import com.hycat.mail.search.service.ProductSaveService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @author : lzhycat
 * @date : 2022-07-29 11:38
 */
@RestController
@RequestMapping("/search/product")
public class ProductSaveController {

    @Resource
    private ProductSaveService productSaveService;

    @PostMapping("/save")
    public R productSpuUp(@RequestBody List<SkuEsModel> skuEsModels) {
        boolean result = true;
        try {
            result = productSaveService.productSpuUp(skuEsModels);
        } catch (IOException e) {
            return R.error(ExceptionEnum.SKU_ES_UP_EXCEPTION);
        }
        if(result) return R.error(ExceptionEnum.SKU_ES_UP_EXCEPTION);
        return R.ok();
    }


    @GetMapping("/search")
    public R productSearch() {
        return R.ok();
    }

}
